/**
 * 
 */
package com.es.business.lead;

import java.util.List;

import org.apache.log4j.Logger;

import com.es.dao.LeadDAO;
import com.es.dao.factory.DAOFactory;
import com.es.exception.business.ESException;
import com.es.exception.dao.ESDataAccessException;
import com.es.model.Lead;

/**
 * @author Bushra Nazir
 *
 */
public class LeadManagementImpl implements ILeadManagement {

	LeadDAO leadDAO = (LeadDAO) DAOFactory.getDataAccessObject(DAOFactory.LEAD_DAO);

	private static final Logger log = Logger.getLogger(LeadManagementImpl.class);

	public Lead createLead(Lead lead) throws ESException{

		log.info("inside  createLead(..) ");
		
		lead.setIsconverted(0);
		lead.setIsqualified(0);
		try{
			int leadId = leadDAO.saveLead(lead);
			return lead;

		} catch (ESDataAccessException e) {
			throw  new ESException(e);
			
		}

	}


	/*
	 * @author Bushra
	 * @param null
	 * @return List<Lead>
	 * @see com.es.business.lead.ILeadManagement#getDeadLeadList()
	 */
	public List<Lead> getDeadLeadList() throws ESException {

		log.info("inside  getDeadLeadList() ");
		List<Lead> deadLeadList;

		try{

			deadLeadList = leadDAO.getAllDeadLeads();
		}catch (ESDataAccessException e) {
			throw  new ESException(e);
		}

		return deadLeadList;
	}



	/* @author Bushra
	 * @see com.es.business.lead.ILeadManagement#deleteDeadLeads(java.util.List)
	 */
	public void deleteDeadLeads(List<String> selectedDeadLeads)
	throws ESException {

		log.info("inside  deleteDeadLeads(..) ");
		log.info("size od list to be deleted :: " + selectedDeadLeads.size());

		for(int i= 0; i<selectedDeadLeads.size(); i++){

			leadDAO.deleteDeadLeadById(Integer.parseInt(selectedDeadLeads.get(i)));

		}


	}


	/* 
	 * @author Bushra
	 * @param null
	 * @result List<Lead>
	 * @see com.es.business.lead.ILeadManagement#getLeadList()
	 */
	public List<Lead> getLeadList() throws ESException{

		log.info("inside  getLeadList() ");
		List<Lead> leadList;

		try{

			leadList = leadDAO.getAllLeads();
			log.info("LEAD LIST SIZE :: " + leadList.size());

			return leadList;

		}catch (ESDataAccessException e) {
			throw  new ESException(e);
		}


	}


	/* 
	 * @author Bushra
	 * @param Integer leadId
	 * @return Lead
	 * @see com.es.business.lead.ILeadManagement#getLead(java.lang.Integer)
	 */
	public Lead getLead(Integer selectedLeadId) throws ESException {

		log.info("inside  getLead(..) ");
		try{

			Lead selectedLead = leadDAO.getLeadByLeadId(selectedLeadId);
			return selectedLead;
			
		}catch (ESDataAccessException e) {
			throw  new ESException(e);
		}


		
	}


	public Lead modifyLead(Lead lead) throws ESException {
	
		log.info("inside  modifyLead(..) ");
		try{

			Lead selectedLead = leadDAO.modifyLead(lead);
			return selectedLead;
			
		}catch (ESDataAccessException e) {
			throw  new ESException(e);
		}


		
		
	}






}
